export function getValue(origin: object | null, keysUrl: string, defaultData: any = []): any {
	const keys = keysUrl.split('.');
	let value = (origin || {}) as Record<string, any>;
	for (const key of keys) {
		if (key.includes(':')) {
			const [keyName, index] = key.split(':');
			value = value[keyName][index];
		} else {
			value = value[key];
		}

		if (typeof value === 'undefined' || value === null) {
			value = {};
		}
	}
	return isEmpty(value) ? defaultData : value;
}

export function isEmpty(obj: any) {
	if (obj === null) return true;
	if (obj === undefined) return true;
	if (Object.prototype.toString.call(obj) === '[object Array]' && obj.length === 0) return true;
	if (typeof obj === 'object') return Object.keys(obj).length === 0;
	return false;
}

export function getUid(prefix: string = ''): string {
	return `${prefix}${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
}
